﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Net.Mail;

namespace MikeKappel.Com.CS
{
    /// <summary>
    /// Summary description for Mailer
    /// </summary>
    public static class Mailer
    {
        public static void SendExternalMail(Guid From, Guid To, string subject, string content)
        {

            SendExternalMail(Membership.GetUser(From).Email, Membership.GetUser(To).Email, subject, content);
        }
        public static void SendExternalMail(String From, String To, String subject, String content)
        {
            if (To.Contains(";"))
            {
                SendExternalMail(From, To.Split(';'), subject, content);
            }
            else
            {
                SendExternalMail(new MailAddress(From), new MailAddress(To), new MailAddress(From), subject, content);
            }
        }
        public static void SendExternalMail(String From, String To, String ReplyTo, String subject, String content)
        {
            if (To.Contains(";"))
            {
                SendExternalMail(From, To.Split(';'), ReplyTo, subject, content);
            }
            else
            {
                SendExternalMail(new MailAddress(From), new MailAddress(To), new MailAddress(ReplyTo), subject, content);
            }
        }
        public static void SendExternalMail(MailAddress From, MailAddress To, MailAddress ReplyTo, String subject, String content)
        {

            System.Net.Mail.MailMessage objMailMessage = new System.Net.Mail.MailMessage();
            objMailMessage.IsBodyHtml = true;
            objMailMessage.From = From;
            objMailMessage.To.Add(To);
            if (ReplyTo.Address != From.Address)
                objMailMessage.ReplyTo = ReplyTo;
            objMailMessage.Subject = subject;
            content = content + "<p style=\"font-size:10px;color=777777;\">Message sent form <a href=\"" + HttpContext.Current.Request.Url.Host + "\" taregt=\"Blank\">" + HttpContext.Current.Request.Url.Host + "</a></p>";
            objMailMessage.Body = content;

            System.Net.Mail.SmtpClient objSMTPClient = new System.Net.Mail.SmtpClient();
            objSMTPClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            objSMTPClient.Send(objMailMessage);
        }
        public static void SendExternalMail(String From, String[] Recipients, String subject, String content)
        {
            for (Int32 i = 0; i < Recipients.Length; i++)
            {
                if (Recipients[i].Length > 0 && Recipients[i].Contains("@") && Recipients[i].Contains("."))
                {
                    SendExternalMail(From, Recipients[i], subject, content);
                }
            }
        }
        public static void SendExternalMail(String From, String[] Recipients, String ReplyTo, String subject, String content)
        {
            for (Int32 i = 0; i < Recipients.Length; i++)
            {
                if (Recipients[i].Length > 0 && Recipients[i].Contains("@") && Recipients[i].Contains("."))
                {
                    SendExternalMail(From, Recipients[i], ReplyTo, subject, content);
                }
            }
        }
    }

}
